package com.bskj.bms.Utils;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.MessagingException;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class MailService {
	private static final String HOST = "smtp.qq.com";//发送服务器地址
    private static final Integer PORT = 465;//发送服务器端口号
    private static final String USERNAME = "2053397959"//用户名
    		+ "";
    private static final String PASSWORD = "ffjbrvpcdujjcigf";//验证码
    private static final String EMAILFORM = "2053397959@qq.com";//发件邮箱号

    private static final String[] TOEMAILS={"txc@boshukeji.com","ls@boshukeji.com","mx@boshukeji.com","wlm@boshukeji.com","yyf@boshukeji.com"};//收件邮箱数组
    /**
     * 发送邮件
     *
     * @param to 接受人
     * @param subject 主题
     * @param html 发送内容
     * @throws MessagingException 异常
     * @throws UnsupportedEncodingException 异常
     */
    public static void sendHtmlMail( String html) throws MessagingException,UnsupportedEncodingException {
    	JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost(HOST);
        sender.setPort(PORT);
        sender.setUsername(USERNAME);
        sender.setPassword(PASSWORD);
        sender.setDefaultEncoding("Utf-8");
        
        Properties pop = new Properties();
        pop.put("mail.smtp.host", HOST);
        pop.put("mail.smtp.auth","true");
        pop.put("mail.smtp.starttls.enable","true");
        pop.put("mail.smtp.timeout", "30000");
        pop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        sender.setJavaMailProperties(pop);
        
    	SimpleMailMessage message = new SimpleMailMessage(); 
    	message.setFrom(EMAILFORM);
    	message.setTo(TOEMAILS);
    	message.setSubject(html+"警告"); 
    	message.setText(html+"停车场半小时无数据");
    	sender.send(message); 
    	System.out.println("send end....");
    }
}
